﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.woodsoft.core;
using com.woodsoft.core.Files;
using EQ1.Elements;
using EQ1.Objects;

namespace EQ1.Templates {
  public class WindowDrawTemplate : UIClass , IUIElement<WindowDrawTemplate> {
    public WindowDrawTemplate ( UIDocument doc , string name )
      : base( doc , name ) {
    }
    public WindowDrawTemplate ( UIDocument doc )
      : this( doc , "WindowDrawTemplate" ) {
    }

    public string Background {
      get {
        return this.GetElement( "Background" ).InnerText;
      }
      set {
        this.Validate( "Background" , value );
      }
    }
    public int BackgroundDrawType {
      get {
        return int.Parse( this.GetElement( "BackgroundDrawType" ).InnerText );
      }
      set {
        this.Validate( "BackgroundDrawType" , value.ToString() );
      }
    }
    public ScrollbarDrawTemplate VSBTemplate {
      get {
        return ( ScrollbarDrawTemplate ) this.GetElement( "VSBTemplate" );
      }
      set {
        this.VSBTemplate.Validate( value , "VSBTemplate" );
      }
    }
    public ScrollbarDrawTemplate HSBTemplate {
      get {
        return ( ScrollbarDrawTemplate ) this.GetElement( "HSBTemplate" );
      }
      set {
        this.HSBTemplate.Validate( value , "HSBTemplate" );
      }
    }
    public ButtonDrawTemplate CloseBox {
      get {
        return ( ButtonDrawTemplate ) this.GetElement( "CloseBox" );
      }
      set {
        this.CloseBox.Validate( value , "CloseBox" );
      }
    }
    public ButtonDrawTemplate QMarkBox {
      get {
        return ( ButtonDrawTemplate ) this.GetElement( "QMarkBox" );
      }
      set {
        this.QMarkBox.Validate( value , "QMarkBox" );
      }
    }
    public ButtonDrawTemplate MinimizeBox {
      get {
        return ( ButtonDrawTemplate ) this.GetElement( "MinimizeBox" );
      }
      set {
        this.MinimizeBox.Validate( value , "MinimizeBox" );
      }
    }
    public ButtonDrawTemplate MaximizeBox {
      get {
        return ( ButtonDrawTemplate ) this.GetElement( "MaximizeBox" );
      }
      set {
        this.MaximizeBox.Validate( value , "MaximizeBox" );
      }
    }
    public ButtonDrawTemplate TileBox {
      get {
        return ( ButtonDrawTemplate ) this.GetElement( "TileBox" );
      }
      set {
        this.TileBox.Validate( value , "TileBox" );
      }
    }
    public FrameTemplate Border {
      get {
        return ( FrameTemplate ) this.GetElement( "Border" );
      }
      set {
        this.Border.Validate( value , "Border" );
      }
    }
    public FrameTemplate Titlebar {
      get {
        return ( FrameTemplate ) this.GetElement( "Titlebar" );
      }
      set {
        this.Titlebar.Validate( value , "Titlebar" );
      }
    }

    #region IUIElement<WindowDrawTemplate> Members
    public void Copy ( WindowDrawTemplate val ) {
      base.Copy( val );

      this.BackgroundDrawType = val.BackgroundDrawType;
      
      if( !string.IsNullOrEmpty( val.Background ) )
        this.Background = val.Background;
      if( val.VSBTemplate != null )
        this.VSBTemplate = val.VSBTemplate;
      if( val.HSBTemplate != null )
        this.HSBTemplate = val.HSBTemplate;
      if( val.CloseBox != null )
        this.CloseBox = val.CloseBox;
      if( val.QMarkBox != null )
        this.QMarkBox = val.QMarkBox;
      if( val.MinimizeBox != null )
        this.MinimizeBox = val.MinimizeBox;
      if( val.MaximizeBox != null )
        this.MaximizeBox = val.MaximizeBox;
      if( val.TileBox != null )
        this.TileBox = val.TileBox;
      if( val.Border != null )
        this.Border = val.Border;
      if( val.Titlebar != null )
        this.Titlebar = val.Titlebar;
    }
    public void Validate (  WindowDrawTemplate val , string name ) {
      UIClass par = ( UIClass ) this.ParentNode;

      if( val.LocalName != name ) {
        WindowDrawTemplate el = new WindowDrawTemplate( ( UIDocument ) val.OwnerDocument , name );
        el.Copy( val );
        val = el;
      }

      if( par.GetElement( name ) != null )
        par.RemoveElement( name );

      par.AppendChild( val );
    }
    #endregion
  }
}
